﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MJM.CONCURSO.AD;
using MJM.CONCURSO.EN;

namespace MJM.CONCURSO.CN
{
    public static class ParticipanteCN
    {
        public static int Insertar(ParticipanteEN obj)
        {
            obj.Hora = (DateTime.Now.Hour + 100).ToString().Substring(1, 2) + ":" +(DateTime.Now.Minute+100).ToString().Substring(1,2);
            obj.Fecha = DateTime.Now.Year.ToString() + (DateTime.Now.Month + 100).ToString().Substring(1, 2) + (DateTime.Now.Day + 100).ToString().Substring(1, 2);            
            return ParticipanteAD.Insertar(obj);
        }

        public static bool EsParticipante(ParticipanteEN obj)
        {
            obj.Activo = 0;
            List<ParticipanteEN> lst = ParticipanteAD.Listar(obj);
            if (lst.Count == 0)
            {
                obj.Activo = 1;
                lst = ParticipanteAD.Listar(obj);
                if (lst.Count > 0)
                    return true;
            }
            else
                return true;

            return false;
        }

        public static List<ParticipanteEN> ListarActivos(ParticipanteEN obj)
        {
            obj.Activo = 1;
            obj.IDPersona="";
            return ParticipanteAD.Listar(obj);
        }

        public static List<ParticipanteEN> ListarNoActivos(ParticipanteEN obj)
        {
            obj.Activo = 0;
            obj.IDPersona = "";
            return ParticipanteAD.Listar(obj);
        }

        public static ParticipanteEN ObtenerParticipante(ParticipanteEN obj)
        {
            obj.Activo = 0;
            List<ParticipanteEN> lst = ParticipanteAD.Listar(obj);
            if (lst.Count == 0)
            {
                obj.Activo = 1;
                lst = ParticipanteAD.Listar(obj);
                if (lst.Count > 0)
                    return lst[0];
            }
            return lst[0];
        }
    }
}
